﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MarkDownFileSplitter
{
    public partial class FormSetting : Form
    {
        public FormSetting()
        {
            InitializeComponent();
        }

        private void FormSetting_Load(object sender, EventArgs e)
        {
            var a = GlobalSetting.Instance;
            this.comboBox1.SelectedItem = a.StorePlace;
            this.textBox1.Text = a.MinIOAccessKey;
            this.textBox2.Text = a.MinIOSecretKey;
            this.textBoxMinIOUrl.Text = a.MinIOUrl;

            this.comboBoxAIMethod.SelectedItem = a.AIMethod;
            this.textBoxOllamaUrl.Text = a.OllamaUlr;
            this.textBoxOllamaModelName.Text = a.OllamaModelName;

            this.textBox_UmiOCRPath.Text = a.UmiOCRPath;
        }

        private void button_saveConfig_Click(object sender, EventArgs e)
        {
            var a = GlobalSetting.Instance;
            a.StorePlace = this.comboBox1.SelectedItem?.ToString();
            a.MinIOAccessKey = this.textBox1.Text;
            a.MinIOSecretKey = this.textBox2.Text;
            a.MinIOUrl = this.textBoxMinIOUrl.Text;

            a.AIMethod = this.comboBoxAIMethod.SelectedItem?.ToString();
            a.OllamaUlr = this.textBoxOllamaUrl.Text;
            a.OllamaModelName = this.textBoxOllamaModelName.Text;

            a.UmiOCRPath = this.textBox_UmiOCRPath.Text;

            a.SaveToFile();

            MessageBox.Show("保存成功");
            DialogResult = DialogResult.OK;
        }

        private void button_selectUmiOCRPath_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "Executable Files (*.exe)|*.exe";
                openFileDialog.Title = "选择UmiOCR可执行文件";

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    this.textBox_UmiOCRPath.Text = openFileDialog.FileName;
                }
            }
        }
    }
}
